<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>


  <script>
    // 需求本身依赖两个请求
    // 会在内部判断两个请求是否都完成,then里面会包含一个数组结果
    // Promise.all([
    //   new Promise((resolve, reject) => {
    //     $.ajax({
    //       url: 'url1',
    //       success: function (data) {
    //         resolve(data)
    //       }
    //     })
    //   }),
    //   new Promise((resolve, reject) => {
    //     $.ajax({
    //       url: 'url2',
    //       success: function (data) {
    //         resolve(data)
    //       }
    //     })
    //   }),
    // ]).then(results => {
    //   console.log(results[0]);
    //   console.log(results[1]);
    // })


    Promise.all([
      new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve('result1')
        }, 1000)
      }),
      new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve('result2')
        }, 2000)
      }),
    ]).then(results => {
      console.log(results[0]);
      console.log(results[1]);
    })
  </script>
</body>

</html>